<script>
	function showPhotoProfile(input) {
	    if (input.files && input.files[0]) {
	        var reader = new FileReader();	        
	        reader.onload = function (e) {
	            $('#imgPhotoProfile').attr('src', e.target.result);
	            $("#webcamPhoto").val("");
	        }	        
	        reader.readAsDataURL(input.files[0]);	        
	    }
	}

	function cancel(){
		window.close();
	}
	
	function takePhoto(){
		var url="index.php?r=akademik/penerimaan_murid/main/getWebcam&callback=webcamListener";
		var winName = "formWebcam";
		var specs ="menubar=0,scrollbars=1,status=0,titlebar=0,toolbar=0";
		var width=350,height=540;
		var replace = false,onCenter = true;
		w = openWindow(winName,url,width,height,onCenter,specs,replace);
		w.focus();
	}
	
	function classHistory(){
		var url="index.php?r=akSiswa_PNK/classHist&student_id=" + $("#id").val();
		var winName = "classHist";
		var specs ="menubar=0,scrollbars=1,status=0,titlebar=0,toolbar=0";
		var width=550,height=540;
		var replace = false,onCenter = true;
		w = openWindow(winName,url,width,height,onCenter,specs,replace);
		w.focus();
		
	}
	
	function fillAgama(){
		arrAgama = ["Islam","Khatolik","Protestan","Hindu","Budha"];		
		$("#religion").empty();		
		select = document.getElementById("religion");
		var opt = document.createElement('option');
		opt.value = "";
		opt.innerHTML = "[Pilih Agama]";
		select.appendChild(opt);		
		for(i =0; i < arrAgama.length;i++){
			var opt = document.createElement('option');
			opt.value = arrAgama[i];
			opt.innerHTML = arrAgama[i];
			if (arrAgama[i] == "<?php echo $religion; ?>"){
				opt.selected = true;
			}
			select.appendChild(opt);
		}
	}
	
	function fillSuku(){
		arrSuku = ["Bali","Batak","Jawa","Padang","Sunda","Lainnya"];		
		$("#ethnic").empty();		
		select = document.getElementById("ethnic");
		var opt = document.createElement('option');
		opt.value = "";
		opt.innerHTML = "[Pilih Suku]";
		select.appendChild(opt);		
		for(i =0; i < arrSuku.length;i++){
			var opt = document.createElement('option');
			opt.value = arrSuku[i];
			opt.innerHTML = arrSuku[i];
			if (arrSuku[i] == "<?php echo $ethnic; ?>"){
				opt.selected = true;
			}
			select.appendChild(opt);
		}
	}
	function save(){
		$("#frmSubmit").submit();
	}

	
	function showWebcam(){
		
	}

	function webcamListener(obj){
		//alert("webcam listener..");
		$('#imgPhotoProfile').attr("src","data:image/jpg;base64," + obj);
		$("#webcamPhoto").val(obj);
		//$('#photoProfile').val(obj);
		var fd = new FormData(document.forms[0]);
		console.log(fd);
			
		//console.log(obj);
	}
		
	$(function(){
		$("#photoProfile").change(function(){
			showPhotoProfile(this);
		});				
	});	
</script>
<div style="width:1000px">
	<div style="border-bottom:2px solid #000;padding-bottom:5px;margin-bottom:20px">
	<?php 
		$this->widget('application.components.widgets.ActionBar', 
			array("menuAlign" => "right", 
				'items' => array(
					array(
						'id' => "btnTakePhoto",
						'title' => "Ambil Foto",
						'icon' => "images/action/webcam-icon.png",
						'callback'=>"takePhoto"
					),
					array(
							'id' => "btnClassHist",
							'title' => "Riwayat Kelas",
							'icon' => "images/action/URL-history-icon.png",
							'callback'=>"classHistory",
							'hidden'=>$op == "add"?true:false,
					),
					array(
						'id' => "btnSave",
						'title' => "Simpan",
						'icon' => "images/action/Actions-document-save-all-icon.png",
						'callback'=>"save"
					),					
					array(
						'id' => "btnCancel",
						'title' => "Batal",
						'icon' => "images/action/Actions-dialog-cancel-icon.png",
						'callback'=>"cancel"
					),
				)
			)
		);
	?>
	</div>
	
	<form id="frmSubmit" action="index.php?r=akademik/penerimaan_murid/main/edit" method="POST" enctype='multipart/form-data' >		
		<?php
			$labelWidth ="100px";			
		?>
		
		<div style="width:100%">
			<div>
				<input type="hidden" id="id" name="id" value="<?php echo $id; ?>" size =10/>
				<input type="hidden" id="op" name="op" value="<?php echo $op; ?>" size =10/></br>
			</div>
			<div>
				<label class="form mandatory" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Department");?></label>
				<label class="form mandatory" style="width:10px">:</label>
				<label class="form" style="width:200px"><?php echo $department_id ;?></label>
				<input type="hidden" id="department_id" name="department_id" value="<?php echo $department_id;?>" size="20" readonly class="disabled" />
				
				<label class="form mandatory" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Tingkat");?></label>
				<label class="form mandatory" style="width:10px">:</label>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo $tingkatan_name ;?></label>
				
				
			</div>
			<div>
				<label class="form mandatory" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Tahun Ajaran");?></label>
				<label class="form mandatory" style="width:10px">:</label>
				<label class="form" style="width:200px"><?php echo $tahun_ajaran["name"] ;?></label>
				<input type="hidden" id="tahun_ajaran_id" name="tahun_ajaran_id" value="<?php echo $tahun_ajaran["id"];?>" size="20" readonly class="disabled"/>
				
				<label class="form mandatory" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Kelas");?></label>
				<label class="form mandatory" style="width:10px">:</label>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo $kelas_name ;?></label>
								
			</div>
			<div><input id="is_active" name="is_active" type="checkbox" <?php echo $is_active?"checked":""; ?> /> <label>Active</label></div>
		</div>
		
		<hr>
		
		<div style="float:left;width:45%;border-right:3px solid #000" >
			<div style="margin-top:0px;"><h2 style="color:#1F2357;font-weight:bold">| Informasi Siswa <h2></div>
			
			<div style="float:left">
				<img id="imgPhotoProfile" src="<?php echo $imgPhotoProfile;?>" alt="" style="width:120px;height:140px;border:1px solid #2B3856"/>
			</div>
			<div style="float:left;margin-left:10px">
				<div>
					<label class="form mandatory" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","ID Siswa");?></label><input type="text" id="sid" name="sid" value="<?php echo $sid;?>" size="20" disabled />
				</div>				
				<div>
					<?php $this->widget('application.components.widgets.TextField', 
						array("name"=>"name","value"=>$name,"htmlOptions"=>"size='20'",
							"label"=>array("value"=>Yii::t("label","Nama"),"htmlOptions"=>"class='form mandatory' style='width:$labelWidth'")
						));
					?>
				</div>
				<div>
					<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Pangilan");?></label><input type="text" id="nick_name" name="nick_name" value="<?php echo $nick_name;?>" size="20" />
				</div>
				<div>
					<label class="form mandatory" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Jenis Kelamin");?></label>
					<input type="radio" name="gender" value="L" <?php echo $gender=="L"?"checked":"";?>  /> Laki-Laki
					<input type="radio" name="gender" value="P" <?php echo $gender=="P"?"checked":"";?> /> Perempuan					
				</div>
				<div>
					<label class="form mandatory" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Tempat Lahir");?></label><input type="text" id="birth_place" name="birth_place" value="<?php echo $birth_place;?>" size="20" />
				</div>
				<div>
					<?php $this->widget('application.components.widgets.DateTextField', 
						array("name"=>"birth_date","value"=>$birth_date,"htmlOptions"=>"size='20'",
							"label"=>array("value"=>Yii::t("label","Tanggal Lahir"),"htmlOptions"=>"class='form mandatory' style='width:$labelWidth'")
						));
					?>
				</div>
					 
							
			</div>			
			<div style="clear:both"></div>
			<div>
				<label class="form" style="display:none;width:<?php echo $labelWidth;?>">Photo Profile</label> 
				<input type='file' id="photoProfile" name="photoProfile"/>
			</div>	
			<div>
				<textarea style="display:none" id="webcamPhoto" name="webcamPhoto"></textarea>
			</div>
			
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Agama");?></label><select id="religion" name="religion" style="width:150px"></select>
			</div>
			<script type="text/javascript">fillAgama();</script>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Suku");?></label><select id="ethnic" name="ethnic" style="width:150px"></select>
			</div>
			<script type="text/javascript">fillSuku();</script>
			
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Kewarganegaraan");?></label>
					<input type="radio" name="citizenship" value="WNI" <?php echo $citizenship == "WNI"?"checked":"";?>  /> WNI
					<input type="radio" name="citizenship" value="WNA" <?php echo $citizenship=="WNA"?"checked":"";?> /> WNA
			</div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>;vertical-align:top"><?php echo Yii::t("label","Alamat");?></label><textarea id="address" name="address" style="width:285px;height:87px"><?php echo $address; ?></textarea>						
			</div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Kode Pos");?></label><input type="text" id="post_code" name="post_code" value="<?php echo $post_code;?>" size="20" />
			</div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","No. Telp");?></label><input type="text" id="home_phone" name="home_phone" value="<?php echo $home_phone;?>" size="20" />
			</div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Handphone");?></label><input type="text" id="handphone" name="handphone" value="<?php echo $handphone;?>" size="20" />				
			</div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Email");?></label><input type="text" id="email" name="email" value="<?php echo $email;?>" size="20" />
			</div>
			
			<div style="margin-top:20px;"><h2 style="color:#1F2357;font-weight:bold">| Data Kesehatan<h2></div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Golongan darah");?></label>
					<input type="radio" name="gol_darah" value="A" <?php echo $gol_darah == "A"?"checked":"";?>  /> A
					<input type="radio" name="gol_darah" value="B" <?php echo $gol_darah=="B"?"checked":"";?> /> B
					<input type="radio" name="gol_darah" value="AB" <?php echo $gol_darah=="AB"?"checked":"";?> /> AB
					<input type="radio" name="gol_darah" value="O" <?php echo $gol_darah=="O"?"checked":"";?> /> O
			</div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Berat");?></label><input type="text" id="berat_kg" name="berat_kg" value="<?php echo $berat_kg;?>" maxlength="3" style="width:20px" />&nbsp; Kg
			</div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Tinggi");?></label><input type="text" id="tinggi_cm" name="tinggi_cm" value="<?php echo $tinggi_cm;?>" maxlength="3" style="width:20px" /> &nbsp;Cm
			</div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>;vertical-align:top"><?php echo Yii::t("label","Riwayat Penyakit");?></label><textarea id="riwayat_penyakit" name="riwayat_penyakit" style="width:285px;height:87px"><?php echo $riwayat_penyakit; ?></textarea>
			</div>
			
		</div>
		<div style="float:right;width:54%;border:0px solid #000"> 
			<div style="margin-top:0px;"><h2 style="color:#1F2357;font-weight:bold">| Orang Tua / Wali<h2></div>
			<div>
				<style>
					#tblOrangTua td{
						padding:0px;
						padding-left:1px;
						padding-right:1px;
					}
					#tblOrangTua td input[type=text]{
						width:90%;
					}
					#tblOrangTua td textarea{
						width:90%;
					}
					
					tr{padding:0px;}
				</style>
				
				<table id="tblOrangTua" style="border:0px solid #000">
					<tr>
						<th style="width:100px"></th><th style="text-align:center">Ayah</th><th style="text-align:center">Ibu</th>
					</tr>
					<tr>
						<td>Nama</td>
						<td><input type="text" id="ayah_nama" name="ayah_nama" value="<?php echo $ayah_nama ?>"/></td>
						<td><input type="text" id="ibu_nama" name="ibu_nama" value="<?php echo $ibu_nama ?>" /></td>						
					</tr>
					<tr>
						<td></td>
						<td><input type="checkbox" id="ayah_almarhum" name="ayah_almarhum" value="<?php echo $ayah_almarhum ?>"/><label> <?php echo Yii::t("label","Almarhum"); ?></label> </td>
						<td><input type="checkbox" id="ibu_almarhum" name="ibu_almarhum" value="<?php echo $ibu_almarhum ?>" /><label> <?php echo Yii::t("label","Almarhum"); ?></label> </td>						
					</tr>
					<tr>
						<td>Pendidikan</td>
						<td><input type="text" id="ayah_pendidikan" name="ayah_pendidikan" value="<?php echo $ayah_pendidikan ?>"/></td>
						<td><input type="text" id="ibu_pendidikan" name="ibu_pendidikan" value="<?php echo $ibu_pendidikan ?>" /></td>						
					</tr>
					<tr>
						<td>Telepon</td>
						<td><input type="text" id="ayah_phone" name="ayah_phone" value="<?php echo $ayah_phone ?>"/></td>
						<td><input type="text" id="ibu_phone" name="ibu_phone" value="<?php echo $ibu_phone ?>" /></td>						
					</tr>
					<tr>
						<td>Handphone</td>
						<td><input type="text" id="ayah_handphone" name="ayah_handphone" value="<?php echo $ayah_handphone ?>"/></td>
						<td><input type="text" id="ibu_handphone" name="ibu_handphone" value="<?php echo $ibu_handphone ?>" /></td>						
					</tr>
					<tr>
						<td><?php echo Yii::t("label","Email");?></td>
						<td><input type="text" id="ayah_email" name="ayah_email" value="<?php echo $ayah_email ?>"/></td>
						<td><input type="text" id="ibu_email" name="ibu_email" value="<?php echo $ibu_email ?>" /></td>						
					</tr>
					<tr>
						<td><?php echo Yii::t("label","Alamat");?></td>
						<td><textarea id="ayah_address" name="ayah_address"><?php echo $ayah_address ?></textarea></td>
						<td><textarea id="ibu_address" name="ibu_address"><?php echo $ibu_address ?></textarea></td>
					</tr>
					<tr>
						<td><?php echo Yii::t("label","Wali");?></td>
						<td colspan=2><input type="text" id="wali_nama" name="wali_nama" value="<?php echo $wali_nama;?>" /></td>
					</tr>
					<tr>
						<td><?php echo Yii::t("label","Hubungan");?></td>
						<td colspan=2><input type="text" id="wali_hubungan" name="wali_hubungan" value="<?php echo $wali_hubungan;?>" /></td>
					</tr>
					
					<tr>
						<td><?php echo Yii::t("label","Alamat");?></td>						
						<td colspan=2><textarea type="text" id="wali_address" name="wali_address"> <?php echo $wali_address;?> </textarea></td>
					</tr>					
				</table>				
			</div>			
			<div style="clear:both"></div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Kontak Utama");?></label>
					<input type="radio" name="prioritas_contact" value="Ayah" <?php echo $prioritas_contact == "Ayah"?"checked":"";?> /> <label style="margin-right:10px">Ayah</label>
					<input type="radio" name="prioritas_contact" value="Ibu" <?php echo $prioritas_contact=="Ibu"?"checked":"";?> /> <label style="margin-right:10px">Ibu </label>
					<input type="radio" name="prioritas_contact" value="Wali" <?php echo $prioritas_contact=="Wali"?"checked":"";?> /> <label style="margin-right:10px">Wali</label>
			</div>
			
			<div style="margin-top:20px;"><h2 style="color:#1F2357;font-weight:bold">| Data Lainnya <h2></div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>;vertical-align:top"><?php echo Yii::t("label","Batasan");?></label><textarea id="restriction" name="restriction" style="width:220px"><?php echo $restriction; ?></textarea>
			</div>
			<div>
				<label class="form" style="width:<?php echo $labelWidth;?>"><?php echo Yii::t("label","Cara Bayar");?></label><select id="payment_method" name="payment_method">
					<option value="Cash" <?php echo $payment_method == "Cash" ?"selected":""?> >Cash</option>
					<option value="BCA VA" <?php echo $payment_method == "BCA VA" ?"selected":""?> >BCA VA</option>
				</select>
				<label class="form" style="width:50px;margin-left:10px"><?php echo Yii::t("label","Referensi");?></label><input type="text" id="ref_payment" name="ref_payment" value="<?php echo $ref_payment; ?>" />
			</div>
			
		</div>
		<div style="clear:both"></div>
	</form>
	
</div>